<template>
  <div class="school">
    <h3>学校名称：{{ name }}</h3>
    <h3>地址：{{ address }}</h3>
  </div>
</template>

<script>
import pubsub from "pubsub-js";

export default {
  name: "School",
  data() {
    return {
      name: "福州大学",
      address: "福州洪山桥",
    };
  },
  methods: {
    demo(value) {
      console.log("school组件收到数据", value);
    },
    getStudentNameMsg(messageName, data) {
      console.log(messageName, "data", data);
    },
  },
  mounted() {
    // this.$bus.$on("demo",this.demo)//可以用箭头函数替代
    this.pubId = pubsub.subscribe("studentNameMsg", this.getStudentNameMsg);
    console.log(pubsub);
  },
  beforeDestroy() {
    // this.$bus.$off("demo")//解绑
    pubsub.unsubscribe(this.pubId);
  },
};
</script>

<style scoped>
.school {
  background-color: red;
  padding: 5px;
}
</style>